package com.cndw.kungfu.model.operation;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;

import com.cndw.kungfu.config.ConstantsRadio;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.general.ModeExpConfig;
import com.cndw.kungfu.vo.EventNotice;

public class WinneCenter {
	private static int signId = 0;

	private static ConcurrentHashMap<Integer, ConcurrentSkipListSet<Long>> openIds = new ConcurrentHashMap<Integer, ConcurrentSkipListSet<Long>>();

	
	public static int getBaseExp(int level) {
		return ModeExpConfig.getExpOnline(level) * 180;
	}

	public static int getOfferExp(int level, int type) {
		int exp = getBaseExp(level);
		if (type == 0) {
			exp = exp * 5 / 100;
		} else if (type == 1) {
			exp = exp / 10;
		} else if (type == 2) {
			exp = exp * 5 / 10;
		} else if (type == 3) {
			exp = exp * 2;
		}
		return exp;
	}

	public synchronized static void open(Player player) {
		signId++;
		Set<Long> onLineIds = Context.getTcpServer().allOnLineIds();
		
		openIds.put(signId, new ConcurrentSkipListSet<Long>(onLineIds));
		EventNotice eventNotice = new EventNotice(ConstantsRadio.meet, ConstantsRadio.meetOepn);
		eventNotice.put("id", player.getPlayerId());
		eventNotice.put("name", player.getPlayerName());
		eventNotice.put("signId", signId);
		eventNotice.broadcast(onLineIds);

	}

	public static boolean isOffer(int sign, long uid) {
		if (openIds.containsKey(sign) && openIds.get(sign).contains(uid)) {
			openIds.get(sign).remove(uid);
			return true;
		}
		return false;
	}

}
